'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.default = addClass;

var _hasClass = require('./hasClass');

var _hasClass2 = _interopRequireDefault(_hasClass);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function addClass(element, className) {
    if (!className) {
        throw new Error('参数"className"不能为空！');
    }
    var classNames = [];

    //原来的class
    if (element.getAttribute('class')) {
        classNames = element.getAttribute('class').split(/\s+/);
    }

    //没有才添加
    if (!(0, _hasClass2.default)(element, className)) {
        //新增的class
        classNames.push(className);

        //更新
        element.setAttribute('class', classNames.join(' '));
    }
}